package linkwechat.controller.system;


import com.github.pagehelper.PageInfo;
import linkwechat.pojo.*;
import linkwechat.sysservice.SysUserService;
import linkwechat.util.Bcrypt;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("sysUser")
@RestController
public class SysUserController {
    @Resource
    SysUserService userService;

    //    查询所有用户
    @RequestMapping("selectAll")
    public ReturnData userListAll(Integer pageNum, Integer pageSize) {
        PageInfo<SysUser> sysUserPageInfo = userService.selectUserList(pageNum, pageSize);
        return ReturnData.respSuccess(sysUserPageInfo);
    }

    //    根据部门查询用户
    @RequestMapping("selectDeptLike")
    public ReturnData userDeptLike(Integer deptId, Integer pageNum, Integer pageSize) {
        PageInfo<SysUser> list = userService.selectDeptLike(deptId, pageNum, pageSize);
        return ReturnData.respSuccess(list);
    }

    //    用户条件查询
    @RequestMapping("selectListLike")
    public ReturnData userListLike(SysUser sysUser, String startTime, String endTime) {
        List<SysUser> list = userService.selectUserLike(sysUser, startTime, endTime);
        return ReturnData.respSuccess(list);
    }

    // 查询所有角色
    @RequestMapping("selectRoleList")
    public ReturnData selectRoleList() {
        List<LinkRole> linkRoles = userService.selectRoleList();
        return ReturnData.respSuccess(linkRoles);
    }

    //   查询用户名 手机号 邮箱 是否唯一
    @RequestMapping("selectUserUnique")
    public ReturnData selectUserUnique(SysUser sysUser) {
        List<SysUser> sysUsers = userService.selectUserUnique(sysUser);
        return ReturnData.respSuccess(sysUsers);
    }


    //    新增用户
    @RequestMapping("insertUser")
    public ReturnData insertUser(SysUser sysUser) {
        sysUser.setPassword(Bcrypt.BaryPass(sysUser.getPassword()));
        int i = userService.insertUser(sysUser);
        return ReturnData.setResp(ReturnEnum.APPEND_SUCCEED, i);
    }

    //    修改用户
    @RequestMapping("updateUser")
    public ReturnData updateUser(SysUser sysUser) {
        int i = userService.updateUser(sysUser);
        return ReturnData.setResp(ReturnEnum.MODIFY_SUCCEED, i);
    }

    //    修改用户状态
    @RequestMapping("upUserStatus")
    public ReturnData upUserStatus(SysUser sysUser){
        int i = userService.updateUserStatus(sysUser);
        return ReturnData.setResp(ReturnEnum.MODIFY_SUCCEED, i);
    }


    @RequestMapping("deleteUserById")
    public ReturnData deleteUserById(Long userId) {
        int i = userService.deleteUserById(userId);
        return ReturnData.setResp(ReturnEnum.REMOVE_SUCCEED, i);
    }


    @RequestMapping("deleteUserByIds")
    public ReturnData deleteUserByIds(Long[] userIds) {
        System.out.println(userIds);
        int i = userService.deleteUserByIds(userIds);
        return ReturnData.setResp(ReturnEnum.REMOVE_SUCCEED, i);
    }






}
